package com.kaka.service.serviceimpl;

import com.kaka.mapper.PermissionMapper;
import com.kaka.mapper.RolePermissionMapper;
import com.kaka.pojo.Permission;
import com.kaka.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionMapper permissionMapper;

    @Autowired
    private RolePermissionMapper rolePermissionMapper;

    @Override
    public List<Permission> findAll() {
        return permissionMapper.selectAll();
    }

    @Override
    public Permission findById(int id) {
        return permissionMapper.selectById(id);
    }

    @Override
    public int edit(Permission permission) {
        return permissionMapper.updatePermission(permission);
    }

    @Override
    public int addPermission(Permission permission) {
        return permissionMapper.addPermission(permission);
    }

    @Override
    @Transactional
    public int deletePermission(int id) {
        int i = rolePermissionMapper.deleteByPid(id);
        int j = permissionMapper.deleteById(id);
        return i + j;
    }

    @Override
    public List<Permission> selectByRid(int rid) {
        return permissionMapper.selectByRid(rid);
    }

    @Override
    public List<Permission> findByUid(int uid) {
        return permissionMapper.selectByUid(uid);
    }
}
